<?php
	if(!defined('BASEPATH'))
		exit('No direct script access allowed');
	class Admin_Module_Model extends CI_Controller {
		function __construct(){
			parent::__construct();
		}
		
		function usermanagement_all_modules($sort_ord,$order_by){
			if($order_by == 'module_name'){
				$base_url = 'http://localhost/azindia/azindia-client/index.php/admin/module_ctrl/module_name_sort/';
			}elseif($order_by == 'sequence'){
				$base_url = 'http://localhost/azindia/azindia-client/index.php/admin/module_ctrl/sequence_sort/';
			}elseif($order_by == 'created_date'){
				$base_url = 'http://localhost/azindia/azindia-client/index.php/admin/module_ctrl/created_date_sort/';
			}else{
				$base_url = 'http://localhost/azindia/azindia-client/index.php/admin/module_ctrl/index/';
			}
			if($this->uri->segment(4)){
				$current_page = $this->uri->segment(4);
			}else{
				$current_page = 0;
			}			
			$results_per_page = 3;
		
		
			$url = 'http://localhost/azindia/azindia-api/json.api';
			$data = array('www-command'=>'usermanagement-all_modules', 'current_page'=>$current_page, 'results_per_page'=>$results_per_page,'order_by'=>$order_by,'sort_order'=>$sort_ord);
			
			$string = http_build_query($data);
			//echo '<pre>';print_r($data);exit;
			$ch = curl_init($url);
			curl_setopt($ch,CURLOPT_POST,true);
			curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
			curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
			$response= json_decode(curl_exec($ch));
			$data['usermanagement_all_modules'] = $response;
			//echo '<pre>';print_r($response);exit;
			curl_close($ch);
		
			$this->load->library('pagination');			
			$config['base_url'] = $base_url;
			$config['per_page'] = $results_per_page;
			$config['total_rows']  = $response->total;
			$config['uri_segment'] = 4;
			$config['num_links'] = 1;
			$config['prev_link'] = 'Previous';
			$config['next_link'] = 'Next';
			$config['first_link'] = 'First';
			$config['last_link'] = 'Last';
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			$this->load->view('admin/module_view', $data);
		}
		
	}